import entity.Person;

import java.lang.reflect.*;

public class Shangji1 {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Class clz = Person.class;

        String name = clz.getName();



        System.out.println("类名："+name);

        System.out.println("-------------------------------------");

        int modifier = clz.getModifiers();

        System.out.println(name+"类的修饰符");
        if ((modifier & Modifier.PUBLIC) == Modifier.PUBLIC) {
            System.out.println("\t访问修饰符：public");
        }else {
            System.out.println("\t访问修饰符：default(package)");
        }
        if ((modifier & Modifier.FINAL) == Modifier.FINAL) {
            System.out.println("\t这个类是final的");
        }
        if ((modifier & Modifier.ABSTRACT) == Modifier.ABSTRACT) {
            System.out.println("\t这个一个抽象类");
        }
        if ((modifier & Modifier.INTERFACE) == Modifier.INTERFACE) {
            System.out.println("\t这个一个接口");
        }

        System.out.println();
        System.out.println("-------------------------------------");

        Constructor[] cons = Person.class.getDeclaredConstructors();

        System.out.println("访问修饰符：");

        for (Constructor con : cons) {
            if ((modifier & Modifier.PUBLIC) == Modifier.PUBLIC)
                System.out.println("public");

            else if ((modifier & Modifier.PROTECTED) == Modifier.PROTECTED)
                System.out.println("protected");

            else if ((modifier & Modifier.PRIVATE) == Modifier.PRIVATE)
                System.out.println("private");
            else
                System.out.println("default(package)");

            Class[] params = con.getParameterTypes();
            if (params.length == 0) {
                System.out.println("改构造方法没有参数");
            }else {
                System.out.print("改构造方法和参数列表为：[");
                for (int i = 0; i < params.length; i++) {
                    if (i != 0) {
                        System.out.print(", ");
                        System.out.print(params[i].getName());
                    }
                    System.out.println("]");
                }
            }

        }
        System.out.println("-----------------------------------");

        Field[] fields = Person.class.getDeclaredFields();

        for (Field field : fields) {
            System.out.println("属性名：" + field.getName());
            System.out.println("类型：" + field.getType().getName());
            System.out.println("--------------------------");
        }


        Method[] methods = Person.class.getDeclaredMethods();

        for (Method method : methods) {
            System.out.println("方法名："+method.getName());
            System.out.println("返回值类型"+method.getReturnType().getName());
            System.out.println("--------------------------");
        }





    }
}
